package com.fr.plugin.export.xml.core;

import com.fanruan.api.report.export.BaseOperate;
import com.fr.general.DeclareRecordType;
import com.fr.io.collection.ExportCollection;
import com.fr.plugin.export.xml.exporter.XmlExporter;
import com.fr.stable.web.SessionProvider;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by richie on 16/1/19.
 */
public class XmlExportOperate extends BaseOperate {

    @Override
    public void setContent(HttpServletRequest req, HttpServletResponse res, String fileName, boolean isEmbed) {
        res.setContentType("application/octet-stream");
        res.setHeader("extension", "xml");
        res.setHeader("Content-disposition", "attachment; filename=" + fileName + ".xml");
    }

    @Override
    public ExportCollection newExportCollection(HttpServletRequest req, HttpServletResponse res, SessionProvider sessionIDInfor, String fileName) {
        ExportCollection collection = ExportCollection.create();
        collection.setExporter(new XmlExporter());
        collection.setRecordType(DeclareRecordType.EXPORT_TYPE_CSV);

        return collection;
    }
}